﻿(function ($) {
    app.modals.CreateOrEditModal = function () {

        var _classroomService = abp.services.app.classroom;
        var _modalManager;
        var _$form = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$form = _modalManager.getModal().find('form[name=ObjectForm]');
            _$form.validate();
        };

        this.save = function () {
            if (!_$form.valid()) {
                return;
            }

            var domainObject = _$form.serializeFormToObject();

            _modalManager.setBusy(true);
            _classroomService.createOrUpdateObject({
                classroom: domainObject
            }).done(function (result) {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.setResult(result);
                _modalManager.close();
                abp.event.trigger('app.CreateOrEditModalSaved', result);
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
})(jQuery);